package com.gitee.feizns.quickstart.ding.talk.api.top.api.v2.user;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiV2UserCreateRequest;
import com.dingtalk.api.response.OapiV2UserCreateResponse;
import com.dingtalk.api.response.OapiV2UserGetResponse;
import com.gitee.feizns.quickstart.ding.talk.utils.Utils;
import lombok.SneakyThrows;

/**
 * 创建用户（/topapi/v2/user/create）
 * 接口路径：<a href="https://open.dingtalk.com/document/orgapp/user-information-creation">创建用户（/topapi/v2/user/create）</a>
 * @link <a href="https://open.dingtalk.com/document/orgapp/user-information-creation">服务端API 通讯录管理 用户管理 创建用户</a>
 * @author feizns
 * @since 2025/3/24
 */
public class Create {

    /**
     * 执行
     * @param accessToken 访问令牌
     * @param req 要求
     * @return {@link OapiV2UserGetResponse.UserGetResponse }
     */
    @SneakyThrows
    public static OapiV2UserCreateResponse.UserCreateResponse execute(String accessToken, OapiV2UserCreateRequest req) {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/create");
        OapiV2UserCreateResponse rsp = client.execute(req, accessToken);
        return Utils.ifErrorThrow(rsp).getResult();
    }

}
